﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Business_Layer;
using DTO;

/// <summary>
/// Summary description for Retailer_WS
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Retailer_WS : System.Web.Services.WebService
{

    public Retailer_WS()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    Dictionary<string, string> sids = new Dictionary<string, string>();

    [WebMethod(EnableSession = true)]
    public string DangNhap(string tenDangNhap, string matKhau)
    {
        sids = (Dictionary<string, string>)Session["SID"];
        if (sids == null)
        {
            sids = new Dictionary<string, string>();
        }

        if (NhaCungCapBUS.kiemTraDangNhap(tenDangNhap, matKhau))
        {
            string sid = HttpContext.Current.Session.SessionID;
            sids.Add(sid, tenDangNhap);
            Session["SID"] = sids;
            return sid;
        }

        return null;
    }

    [WebMethod(EnableSession = true)]
    public List<MaSPMucNhapKhoSLTonDTO> layTTQLKho(string sid)
    {
        if (sid.Equals("ThayTest"))
        {
            return SanPhamBUS.layTTQLKho("NhaCungCapEM03");
        }

        sids = (Dictionary<string, string>)Session["SID"];
        if (sids != null && sids.ContainsKey(sid))
        {
            return SanPhamBUS.layTTQLKho(sids[sid]);
        }

        return null;
    }

    [WebMethod(EnableSession = true)]
    public bool capNhatSLTon(string sid, long maSanPham, long soLuongTon)
    {
        if (sid.Equals("ThayTest"))
        {
            return SanPhamBUS.capNhatSLTon("NhaCungCapEM03", maSanPham, soLuongTon);
        }

        sids = (Dictionary<string, string>)Session["SID"];
        if (sids != null && sids.ContainsKey(sid))
        {
            return SanPhamBUS.capNhatSLTon(sids[sid], maSanPham, soLuongTon);
        }

        return false;
    }
}
